//
//  UIView+QLXExt.h
//  fcuhConsumer
//
//  Created by 邱良雄 on 15/8/7.
//  Copyright (c) 2015年 avatar. All rights reserved.
//

#import <UIKit/UIKit.h>

#define kW(value) ([UIView scaleX]*(value))
#define kH(value) ([UIView scaleY]*(value))
#define kH2(value,value2) ( kH((value) + (value2)) - value2)

//1234 上左下右
typedef NS_ENUM(NSUInteger, ExceptType) {
    ExceptTypeTop = 1,
    ExceptTypeLeft = 2,
    ExceptTypeBottom = 3,
    ExceptTypeRight = 4
};

@protocol UIViewDelegate <NSObject>
@optional
/**
 *   添加子view后 提醒
 */
-(void) view:(UIView *)view didAddSubview:(UIView *)subView;
@end

typedef void (^VoidClorse)();

@interface UIView (CYExt)

@property (nonatomic, strong) NSNumber * firstEnter;
@property (nonatomic, weak)id<UIViewDelegate> viewDelegate;
@property (nonatomic, copy) VoidClorse nextLoopCallback;
@property(nonatomic , assign) UIEdgeInsets  touchFrameAddEdge;   // 扩增view的触摸区域  该原来frame基础上增加edge

#pragma mark - 直接获取以及修改view的长宽xy等
/**********************直接获取以及修改view的长宽xy等**********************/
- (CGFloat)width;

- (void)setWidth:(CGFloat)width;

- (CGFloat)height;

- (void)setHeight:(CGFloat)height;

- (CGPoint)leftTop;

- (void)setLeftTop:(CGPoint)leftTop;

- (CGPoint)rightBottom;

- (void)setRightBottom:(CGPoint)rightBottom;

- (void)setLeft:(CGFloat)left;

- (CGFloat)left;

- (void)setRight:(CGFloat)right;

- (CGFloat)right;

- (void)setX:(CGFloat)x;

- (CGFloat)x;

- (void)setY:(CGFloat)y;

- (CGFloat)y;

- (void)setCenterX:(CGFloat)centerX;

- (CGFloat)centerX;

- (void)setCenterY:(CGFloat)centerY;

- (CGFloat)centerY;

- (void)setSize:(CGSize)size;

- (CGSize)size;

-(CGSize) getLayoutSize;

/**********************设置特殊Frame (加上导航栏高度)**********************/
-(void)setFrame:(CGRect)orgFrame WithNavgBarHeight:(CGFloat)navbarHeight;

//#pragma mark - 动画相关
///**********************动画相关**********************/
//-(void) animateWithShakeWithDuration:(CGFloat) duration force:(CGFloat) force ;
//-(void) animateWithShake;
//-(void) animateFromBootomToShow;
//-(void) animateFromBootomToHidden:(BOOL) completeRemoved;
//-(void) animateFromRightToShow;
//-(void) animateFromRightToHiden:(BOOL) completeRemoved;
//-(void) animateWithFromScale:(CGFloat)from toScale:(CGFloat)to;
//-(void) animateWithFromScale:(CGFloat)from toScale:(CGFloat)to damp:(CGFloat) damp;

#pragma mark - 手势相关
/**********************手势相关**********************/
/**
 *  添加单击手势
 *  它自动帮你交互属性设置为true
 */
-(UITapGestureRecognizer *) addTapGestureRecognizerWithTarget:(id)target action:(SEL) action;

/**
 *  摇动或者拖拽UIPanGestureRecognizer (拖动)
 */
-(UIPanGestureRecognizer *) addPanGestureRecognizerWithTarget:(id)target action:(SEL) action;
/**
 *  擦碰UISwipeGestureRecognizer (以任意方向)
 */
-(UISwipeGestureRecognizer *) addSwipeGestureRecognizerWithTarget:(id)target action:(SEL) action;

/**
 *  旋转UIRotationGestureRecognizer (手指朝相反方向移动)
 */
-(UIRotationGestureRecognizer *) addRotationGestureRecognizerWithTarget:(id)target action:(SEL) action;
/**
 *  长按UILongPressGestureRecognizer (长按)
 */
-(UILongPressGestureRecognizer *) addLongPressGestureRecognizerWithTarget:(id)target action:(SEL) action;
/**
 *  向里或向外捏UIPinchGestureRecognizer (用于缩放)
 */
-(UIPinchGestureRecognizer *) addPinchGestureRecognizerWithTarget:(id)target action:(SEL) action;

#pragma mark - 操控View层级
/********************************************操控View层级********************************************/
/**
 *  调整 层级 扩展
 */
-(NSUInteger)getSubviewIndex;

-(void)bringToFront;

-(void)sendToBack;

-(void)bringOneLevelUp;

-(void)sendOneLevelDown;

-(BOOL)isInFront;

-(BOOL)isAtBack;

-(void)swapDepthsWithView:(UIView*)swapView;

/**隐藏所有子视图*/
-(void) hideSubViews;
-(void) showSubViews;

/**删除所有子视图*/
-(void) removeAllSubivews;


#pragma mark - 伸缩视图
/********************************************伸缩视图********************************************/
/**
 *  设置视图的缩放系数
 *  沿着视图的中心点缩放 缩放的还是可以交互 交互的范围会适应比例变化
 *  @param scale [ 0  , 1]
 */
-(void) setScale:(CGFloat) scale;
/**
 *  设置视图的旋转角度
 *  沿着视图的中心点旋转
 *  M_PI_4  表示顺时针旋转45度
 */
-(void) setRotation:(CGFloat)angle;
/**
 *  缩放视图 相当于整体视图缩放 subview 还会递归下去
 *  @param scale 缩放比例
 */
-(void) scaleFrameOfSubviewsWithScale:(CGFloat)scale;
/**
 *  缩放视图的中心点  用来适配视图大小不变 位置按照原来的百分比来放
 *  @param xScale 横向缩放系数
 *  @param yScale 纵向缩放系数
 */
-(void) scaleCenterOfSubviewsWithXScale:(CGFloat)xScale yScale:(CGFloat) yScale;
-(void) setCornerWithRadius:(CGFloat) radius width:(float)width color:(UIColor *)color;

//边框
-(void)setCornerWithWidth:(float)width color:(UIColor *)color;
//画圆
-(void) setCornerToCircleWidth:(float)width color:(UIColor *)color;
-(void) setCornerWithRadius:(CGFloat)radius;
-(void) setCornerToCircle;


#pragma mark - 其他
/********************************************其他********************************************/
+(instancetype) createFromXib;
-(UINavigationController * ) navigationController;
-(UITabBarController * ) tabBarController;
-(void) arcProgressWithPercentage:(CGFloat) percentage;

/**设置背景*/
-(void)  setBackgroundWithImage:(UIImage *)image;

/** 获取当前view的控制主视图*/
- (UIViewController *)viewController;

/**完全复制自己*/
-(UIView *)copySelf;

/**
 *  将view 渲染成 一张 图片
 *  @return imageSize == view.bounds.size
 */
-(UIImage * ) getImage;

/**
 *  当view 进入到"屏幕"后调用 //下一帧调用 用来初始化一些数据  调用时机在init后面 仅调用一次
 *  或者可以理解为 下一帧调用
 */
-(void) onEnter;

/**
 *  当view 离开"屏幕"后调用
 *  注意: 可能多次调用
 */
-(void) onExit;

/**
 *  下一个runloop 调用
 *  @param block 闭包
 */
-(void) performInNextLoopWithBlock:(VoidClorse) block;

@end
